package com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.common.SessionUser;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.bo.ITXingzhengshouwenNeirongBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengshouwen.vo.ShouWenInfo;
import com.tjsinfo.tjsoa.workflow.WorkFlowTemplate;

public class XingZhengFlowGenZongAction extends Action{
	private ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO;
	
	

	public ITXingzhengshouwenNeirongBO getXingzhengshouwenNeirongBO() {
		return xingzhengshouwenNeirongBO;
	}



	public void setXingzhengshouwenNeirongBO(
			ITXingzhengshouwenNeirongBO xingzhengshouwenNeirongBO) {
		this.xingzhengshouwenNeirongBO = xingzhengshouwenNeirongBO;
	}



	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
		Boolean isZhiShu = false;
		Integer first =  0;
		WorkFlowTemplate workFlowTemplate = new WorkFlowTemplate();
		String path = request.getContextPath();
		String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
		String laiwenjiguan = request.getParameter("laiwenjiguan");
		String laiwenzihao = request.getParameter("laiwenzihao");
		String zhaiyou = request.getParameter("laiwenbiaoti");
		List<ShouWenInfo> faWenInfoList = new ArrayList<ShouWenInfo>();
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			faWenInfoList = xingzhengshouwenNeirongBO.selectXingZhengShouWenGengZong( 0, (0 + 23), laiwenjiguan, laiwenzihao, zhaiyou);

		} else {
			 first = Integer.parseInt(request.getParameter("start"));
			faWenInfoList =  xingzhengshouwenNeirongBO.selectXingZhengShouWenGengZong((first + 1), (first + 23) , laiwenjiguan, laiwenzihao, zhaiyou);
		}
		
		Integer totalProperty = xingzhengshouwenNeirongBO.selectXingZhengShouWenGengZongCount( 0, (0 + 23), laiwenjiguan, laiwenzihao, zhaiyou);		
		object.put("totalProperty", totalProperty);
		for (ShouWenInfo faWenInfo : faWenInfoList) {
			if(faWenInfo.getId() != null){
				JSONObject object2 = new JSONObject(faWenInfo);
				String operateStr = "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+faWenInfo.getFlowId()+"'>跟踪</a>"
						            +"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=selectonedoc&id="+faWenInfo.getId()+"'>查看</a>";
					if (workFlowTemplate.isEnd(Long.valueOf(faWenInfo.getFlowId()) )) {
						object2.put("isend", "end");
					}else if (workFlowTemplate.isSuspend(Long.valueOf(faWenInfo.getFlowId()) )) {
//						object2.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+faWenInfo.getFlowId()+
//							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=selectonedoc&id="+faWenInfo.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:resume("+faWenInfo.getFlowId()+")'>重启</a>"+
//								"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+faWenInfo.getId()+"'>修改</a>"
//								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+faWenInfo.getId()+"'>修改附件</a>");	
						operateStr += "&nbsp;&nbsp;<a href='javascript:resume("+faWenInfo.getFlowId()+")'>重启</a>"
								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+faWenInfo.getId()+"'>修改</a>"
								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+faWenInfo.getId()+"'>修改附件</a>";	
						object2.put("isend", "stop");
					}else{
//						object2.put("operate", "<a href='"+basePath+"documentationflow/xingzhengshouwen/genzong.jsp?flowid="+faWenInfo.getFlowId()+
//							"'>跟踪</a>&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=selectonedoc&id="+faWenInfo.getId()+"'>查看</a>&nbsp;&nbsp;"+"<a href='javascript:suspend("+faWenInfo.getFlowId()+")'>中止</a>"+
//								"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+faWenInfo.getId()+"'>修改</a>"
//								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+faWenInfo.getId()+"'>修改附件</a>"+"&nbsp;&nbsp;<a href='javascript:end("+faWenInfo.getFlowId()+")'>完结</a>");	
						operateStr += "&nbsp;&nbsp;<a href='javascript:suspend("+faWenInfo.getFlowId()+")'>中止</a>"
								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugai&id="+faWenInfo.getId()+"'>修改</a>"
								+"&nbsp;&nbsp;<a href='"+basePath+"tjsinfo/tjsoa/xingzhengshouwen/shenpi.do?method=xiugaifujian&id="+faWenInfo.getId()+"'>修改附件</a>"
								+"&nbsp;&nbsp;<a href='javascript:end("+faWenInfo.getFlowId()+")'>完结</a>";	
						object2.put("isend", "run");
					}
					object2.put("operate",operateStr );	
				array.put(object2);
			}
			
		}
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}

